package com.binhai.springboot.post.servie;

import com.binhai.springboot.post.bean.PostBean;
import com.binhai.springboot.post.dao.PostBeanDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PostService {

    @Autowired
    private PostBeanDao postDao;
    /**
     * 查询所有数据
     * @param
     * @return
     */
    public List getAllData() {

        return postDao.getAllData();
    }


    /**
     * 保存信息
     * @param bean
     * @return
     */
    public Map saveData(PostBean bean) {
        Map re = new HashMap();
        try {
            //保存
          postDao.insertSelective(bean);

            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    /**
     * 修改
     * @param bean
     * @return
     */

    public Map saveShouQuan(PostBean bean) {
        Map re = new HashMap();
        try {
            //删除原有授权
            postDao.deleteShouQuan(bean);
            postDao.saveShouQuan(bean);
            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public String getShouQuan( PostBean bean) {
       return postDao.getShouQuan(bean);
    }

    public List getAllPostTreeData() {
        return  postDao.getAllPostTreeData();
    }

    public Map updateData(PostBean bean) {
        Map re = new HashMap();
        try {
            postDao.update(bean);

            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public Map deleteData(PostBean bean) {
        Map re = new HashMap();
        try {
            postDao.delete(bean);

            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public List selectData(String name) {
        return postDao.select(name);
    }
}
